package com.ruoyi.security.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author yeoman
 * @date 2025/1/15 16:45
 * @description 股票板块编码前缀常量类
 */
@Getter
@AllArgsConstructor
public enum StockBoardCodePrefixEnum {
    /**
     * 主板 main_board
     */
    MB("MB", Lists.newArrayList("600", "601", "603", "605", "000", "001", "002", "003"), "主板"),
    /**
     * 创业板 growth_enterprises_board
     */
    GEB("GEB", Lists.newArrayList("300", "301", "302"), "创业板"),
    /**
     * 科创板 science_technology_innovation_board
     */
    STIB("STIB", Lists.newArrayList("688"), "科创板"),
    /**
     * 北交所 beijing_stock_exchange
     */
    BJSE("BJSE", Lists.newArrayList("43", "83", "87", "88", "920"), "北交所");

    public static String getKeyByStockCode(String stockCode) {
        for (StockBoardCodePrefixEnum value : StockBoardCodePrefixEnum.values()) {
            if (value.prefixes.stream().anyMatch(stockCode::startsWith)) {
                return value.key;
            }
        }
        return null;
    }

    private final String key;
    private final List<String> prefixes;
    private final String desc;

}
